package cn.qiyu5522.tk_ems.service.impl;

import cn.qiyu5522.tk_ems.entity.Dict;
import cn.qiyu5522.tk_ems.entity.JobCategory;
import cn.qiyu5522.tk_ems.mapper.DictMapper;
import cn.qiyu5522.tk_ems.result.R;
import cn.qiyu5522.tk_ems.service.DictService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 数据字典 服务实现类
 * </p>
 *
 * @author Tonkey
 * @since 2023-02-23
 */
@Service
public class DictServiceImpl extends ServiceImpl<DictMapper, Dict> implements DictService {

    @Override
    public R queryDataListByPid(Long parentId) {
        LambdaQueryWrapper<Dict> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(Dict::getParentId,parentId)
                .select(Dict::getId,Dict::getName);
        List<Dict> dictDataList = baseMapper.selectList(lambdaQueryWrapper);
        return R.ok().data("dictDataList",dictDataList);
    }

    @Override
    public R queryDictIdByName(String name) {
        LambdaQueryWrapper<Dict> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(Dict::getName,name)
                .select(Dict::getId,Dict::getName);
        Dict dict = baseMapper.selectOne(lambdaQueryWrapper);
        return R.ok().data("dict",dict);
    }
}
